package com.ikas.ai.framework.statistics.function;

import com.google.common.collect.Lists;
import com.ikas.ai.framework.statistics.StatisticType;

import java.util.List;

/**
 * @Description: 平均数
 * @Author: qi.yilai
 * @Date: 2023/10/27 18:10
 * @Version: 1.0.0
 **/
public class AvgCalcFunction implements CalcFunction<List<? extends Number>, Double, Long, Double> {

    @Override
    public Double calculate(List<? extends Number> list) {
        int count = list.size();
        double sum = 0d;
        sum = list.stream().mapToDouble(Number::doubleValue).sum();
        return sum / count;
    }

    @Override
    public Double calculate(List<? extends Number> list, Double sum, Long count) {
        return sum / count;
    }

    @Override
    public StatisticType type() {
        return StatisticType.AVG;
    }

    public static void main(String[] args) {
        System.out.println(new AvgCalcFunction().calculate(Lists.newArrayList(1, 56f, 43.45, -34.78d)));
    }
}
